from selenium import webdriver
import time

from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By



drivr= webdriver.Firefox()
drivr.maximize_window()
drivr.get('http://www.baidu.com/')
time.sleep(2)


#业务用例执行
#1.输入Web端自动化测试
seach=drivr.find_element(By.ID,'kw')
seach.send_keys('web端自动化测试')

# 2.点击百度一下按钮
# drivr.find_element(By.XPATH,'//*[@id="su"]').click()
seach.send_keys(Keys.ENTER)

# 3.全选搜索框并复制
seach.send_keys(Keys.CONTROL,'a')
seach.send_keys(Keys.CONTROL,'x')

# 4.对设置做鼠标悬停操作
set=drivr.find_element(By.CLASS_NAME,'pf')
#悬停
ActionChains(drivr).move_to_element(set).perform()

# 5.选择高级搜索
time.sleep(2)
drivr.find_element(By.LINK_TEXT,'高级搜索').click()
time.sleep(2)

# 6.粘贴全部复制的内容到第3个框
drivr.find_element(By.NAME,'q3').send_keys(Keys.CONTROL,'v')

# 7.选择时间一周内
drivr.find_element(By.XPATH,'//*[@id="adv-setting-gpc"]/div/div[1]').click()
drivr.find_element(By.XPATH,'//*[@id="adv-setting-gpc"]/div/div[2]/div[2]/p[3]').click()
time.sleep(2)

# 8.选择文档格式pdf
drivr.find_element(By.XPATH,'//*[@id="adv-setting-ft"]/div/div[1]').click()
drivr.find_element(By.XPATH,'//*[@id="adv-setting-ft"]/div/div[2]/div[2]/p[2]').click()
time.sleep(2)

# 9.点击高级搜素
drivr.find_element(By.XPATH,'//*[@id="adv-setting-8"]/input[2]').click()